package com.bootdo.program.wallpaper.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bootdo.common.config.Constant;
import com.bootdo.common.controller.BaseController;
import com.bootdo.program.wallpaper.service.BzConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.program.wallpaper.domain.BzBannerDO;
import com.bootdo.program.wallpaper.service.BzBannerService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 小程序首页轮播图
 * 
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2021-07-08 12:55:21
 */
 
@Controller
@RequestMapping("/wallpaper/bzBanner")
public class BzBannerController  extends BaseController {
	@Autowired
	private BzBannerService bzBannerService;

	@GetMapping()
	@RequiresPermissions("wallpaper:bzBanner:bzBanner")
	String BzBanner(){
	    return "wallpaper/bzBanner/bzBanner";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wallpaper:bzBanner:bzBanner")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//params.put("appid",queryAppid());
		//查询列表数据
        Query query = new Query(params);
		List<BzBannerDO> bzBannerList = bzBannerService.list(query);
		int total = bzBannerService.count(query);
		PageUtils pageUtils = new PageUtils(bzBannerList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wallpaper:bzBanner:add")
	String add(){
	    return "wallpaper/bzBanner/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wallpaper:bzBanner:edit")
	String edit(@PathVariable("id") Integer id,Model model){

		BzBannerDO bzBanner = bzBannerService.get(id);
		model.addAttribute("bzBanner", bzBanner);
	    return "wallpaper/bzBanner/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wallpaper:bzBanner:add")
	public R save( BzBannerDO bzBanner){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		//bzBanner.setAppid(getAppid());
		bzBanner.setCreateTime(new Date());
		if(bzBannerService.save(bzBanner)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wallpaper:bzBanner:edit")
	public R update( BzBannerDO bzBanner){
		String message = getMessage();
		if(null != message){
			return R.error(message);
		}
		//bzBanner.setAppid(getAppid());
		bzBanner.setUpdateTime(new Date());
		bzBannerService.update(bzBanner);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wallpaper:bzBanner:remove")
	public R remove( Integer id){
		if (Constant.DEMO_ACCOUNT.equals(getUsername())) {
			return R.error(1, "演示系统不允许修改,完整体验请部署程序");
		}
		if(bzBannerService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wallpaper:bzBanner:batchRemove")
	public R remove(@RequestParam("ids[]") Integer[] ids){
		bzBannerService.batchRemove(ids);
		return R.ok();
	}
	
}
